package com.ibeeking.found.msg.api.feign.fallback;

import com.ibeeking.found.msg.api.common.dto.MemberInfoDTO;
import com.ibeeking.found.msg.api.common.dto.TagsDefineDTO;
import com.ibeeking.found.msg.api.common.query.FeignTagsDefineQuery;
import com.ibeeking.found.msg.api.feign.MsgMemberBClient;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;
import java.util.Set;

/**
 * 降级工场
 *
 * @Author ibeeking
 * @date 2019/1/18
 */
@Component
public class MsgMemberBFallbackFactory implements FallbackFactory<MsgMemberBClient> {
    @Override
    public MsgMemberBClient create(Throwable throwable) {
        return new MsgMemberBClient() {
            @Override
            public ResponseResult<MemberInfoDTO> infoOne(Long id) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "调用异常 根据会员Id查询会员信息失败。" + throwable.getMessage());
            }

            @Override
            public ResponseResult<List<MemberInfoDTO>> memberInfo(Set<Long> ids) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "调用异常 根据会员Id查询会员信息失败。" + throwable.getMessage());
            }

            @Override
            public ResponseResult<List<TagsDefineDTO>> effectiveManualList(FeignTagsDefineQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，通过标签id查询标签数据失败。");
            }

        };
    }
}
